package org.yzh.scheduler.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.customizers.PropertyCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Set;

@Configuration
public class SwaggerConfig {

    private static final Set<String> ignores = Set.of(
            "createdAt",
            "createdBy",
            "updatedAt",
            "updatedBy"
    );

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("schedule-api")
                        .version("1.0.0"));
    }

    @Bean
    public PropertyCustomizer propertyCustomizer() {
        return (schema, type) -> {
            String name = type.getPropertyName();
            schema.readOnly(ignores.contains(name));
            return schema;
        };
    }
}